﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Data.Xml.Dom;
using Windows.UI;
using Windows.UI.Popups;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
using Windows8Accelerator.Core.Xaml.ViewModels;

namespace Windows8Accelerator.Core.Xaml.Controls
{
    public class SuperSplashPageContent : ContentControl
    {
        public SuperSplashPageContent()
        {
            DefaultStyleKey = typeof(SuperSplashPageContent);
        }
    }

    public class SuperSplashPage : Page
    {
        private SuperSplashPageViewModel _ViewModel;
        public SuperSplashPageViewModel ViewModel
        {
            get { return _ViewModel; }
        }

        public SuperSplashPage(SuperSplashPageViewModel viewModel) 
        {
            _ViewModel = viewModel;
            DefaultStyleKey = typeof(SuperSplashPage);
            PageContent = new SuperSplashPageContent();
            Content = PageContent;
            Window.Current.SizeChanged += WindowSizeChanged;
            Loaded += SuperSplashPage_Loaded;
        }

        async void SuperSplashPage_Loaded(object sender, RoutedEventArgs e)
        {
            await ViewModel.LoadAsync();
        }

        void WindowSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
        {
            ViewModel.OnWindowSizeChanged();
        }

        private SuperSplashPageContent PageContent;

        public async Task PreLoadAsync()
        {
            await ViewModel.PreLoadAsync();
            PageContent.Content = ViewModel;
        }
    }
}
